﻿@using System.Globalization
@using BookShop.Library.Common
@using HTN.Library
@model BookShop.Site.Models.OrderCartItemListModel

<div class="goods-data clearfix">
    @if (Model != null)
    {
        if (Model.CartItems != null)
        {
            if (Model.CartItems.Count == 0)
            {
        <p>Giỏ hàng của bạn rỗng. Xin mời tiếp tục mua hàng tại Book Shop Ngân Hà.</p>
            }
            else
            {
                double totalPriceCount = 0;
                var shippingFee = (double)(ViewBag.ShippingFee ?? 0);
        <div class="table-wrapper-responsive">
            <table summary="Shopping cart">
                <tr>
                    <th class="goods-page-image">Ảnh bìa</th>
                    <th class="goods-page-description">Mô tả</th>
                    <th class="goods-page-quantity">Số lượng</th>
                    <th class="goods-page-price">Đơn giá</th>
                    <th class="goods-page-total" colspan="2">Thành tiền</th>
                </tr>
                @foreach (var item in Model.CartItems)
                {
                    if (item.Book == null)
                    {
                        continue;
                    }
                    totalPriceCount += item.UnitPrice * item.Quantity;
                    <tr>
                        <td class="goods-page-image">
                            <a href="javascript:;">
                                <img src="@Utility.UrlCombine(CommonFunction.GetConfigValue("SiteUrl"), item.Book.PictureUrl)" alt="@item.Book.Title"></a>
                        </td>
                        <td class="goods-page-description">
                            <h3><a href="@Url.Action("Detail", "Book", new { bookId = item.Book.Id })">@item.Book.Title</a></h3>
                            <p>Tác giả: @item.Book.AuthorName</p>
                            <em>Thể loại: <a href="@Url.Action("ProductPage", "Home", new { categoryId = item.Book.CategoryId })">@item.Book.CategoryName</a></em>
                        </td>
                        <td class="goods-page-quantity">
                            <div class="product-quantity">
                                <input id="product-quantity" type="text" value="@item.Quantity" readonly class="form-control input-sm">
                            </div>
                        </td>
                        <td class="goods-page-price">
                            <strong>@item.UnitPrice.ToString(CultureInfo.CreateSpecificCulture("en-US"))<span>(Đ)</span>
                                <span class="my-price">
                                    <em>
                                        <span>@item.Book.Price.ToString(CultureInfo.CreateSpecificCulture("en-US"))</span>
                                    </em>
                                </span>
                            </strong>
                        </td>
                        <td class="goods-page-total">
                            <strong>@(item.UnitPrice * item.Quantity)<span>(Đ)</span></strong>
                        </td>
                        @if (Model.IsShoppingCartPage)
                        {
                            <td class="del-goods-col">
                                <a class="del-goods" href="javascript:deleteCartItem('@item.Id');">&nbsp;</a>
                                <a class="add-goods" href="javascript:updateCartItem($('#product-quantity').val(), '@item.Id');">&nbsp;</a>
                            </td>
                        }
                    </tr>
                }
            </table>
        </div>
        <div class="shopping-total">
            <ul>
                <li>
                    <em>Tổng giá trị</em>
                    <strong class="price">@totalPriceCount.ToString(CultureInfo.CreateSpecificCulture("en-US")) (Đ)</strong>
                </li>
                <li>
                    <em>Phí vận chuyển</em>
                    <strong class="price">@shippingFee.ToString(CultureInfo.CreateSpecificCulture("en-US")) (Đ)</strong>
                </li>
                <li class="shopping-total-price">
                    <em>Thành tiền</em>
                    <strong class="price">@((totalPriceCount + shippingFee).ToString(CultureInfo.CreateSpecificCulture("en-US"))) (Đ)</strong>
                </li>
            </ul>
        </div>
            }
        }
    }
    else
    {
        <div class="content-page">
            <p>Giỏ hàng của bạn rỗng. Xin mời tiếp tục mua hàng tại Book Shop Ngân Hà.</p>
        </div>
    }
</div>
